package com.jyb.qiyefuwu.view.activity.usercenter;


import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.jyb.qiyefuwu.R;
import com.jyb.qiyefuwu.databinding.ActivitySetMarkBinding;
import com.jyb.qiyefuwu.viewmodel.SalesOderDetailsModel;
import com.sgb.link.constant.RequestCode;
import com.sgb.link.router.PathEnterpriseServices;
import com.swgk.core.common.base.BaseActivity;
import com.swgk.core.util.MToast;


/**
 * 作者:陈方凯
 * 日期:2021/09/28
 * 说明:修改备注
 */
@Route(path = PathEnterpriseServices.SetMarkActivity)
public class SetMarkActivity extends BaseActivity<SalesOderDetailsModel, ActivitySetMarkBinding> {
    private String mark;
    private String id;

    @Override
    protected int layoutId() {
        return R.layout.activity_set_mark;
    }

    @Override
    protected void createViewModel() {
        mViewModel = new ViewModelProvider(this).get(SalesOderDetailsModel.class);
    }

    @Override
    protected void init() {
        mark = getIntent().getStringExtra("mark");
        id = getIntent().getStringExtra("id");
        mBinding.et.setText(mark);
        mBinding.backView.setOnClickListener(this);
        mBinding.tvCommit.setOnClickListener(this);

        mViewModel.updateMark.observe(this, new Observer<String>() {
            @Override
            public void onChanged(String s) {
                Intent mintent = new Intent();
                mintent.putExtra("data", mBinding.et.getText().toString());
                setResult(RequestCode.CODE_ZERO, mintent);
                finish();
            }
        });
    }


    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.back_view) {
            finish();
        } else if (id == R.id.tv_commit) {
            if (TextUtils.isEmpty(mBinding.et.getText().toString())) {
                MToast.showToast(SetMarkActivity.this, "请输入备注");
                return;
            }
            mViewModel.updateNote(this.id, mBinding.et.getText().toString());
        }
    }
}
